package com.xjy.system.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xjy.common.core.mybatisplus.core.ServicePlusImpl;
import com.xjy.common.core.page.PagePlus;
import com.xjy.common.core.page.TableDataInfo;
import com.xjy.common.utils.PageUtils;
import com.xjy.system.domain.ReportLoanDetail;
import com.xjy.system.domain.ReportLoanRecord;
import com.xjy.system.domain.bo.ReportLoanRecordQueryBo;
import com.xjy.system.domain.vo.ReportLoanRecordVo;
import com.xjy.system.mapper.ReportLoanRecordMapper;
import com.xjy.system.service.IReportLoanRecordService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 归还(冲销)记录Service业务层处理
 *
 * @author mlb
 * @date 2022-03-23
 */
@Service
public class ReportLoanRecordServiceImpl extends ServicePlusImpl<ReportLoanRecordMapper, ReportLoanRecord> implements IReportLoanRecordService {

    @Override
    public ReportLoanRecordVo queryById(Long projId){
        return getVoById(projId, ReportLoanRecordVo.class);
    }

    @Override
    public TableDataInfo<ReportLoanRecordVo> queryPageList(ReportLoanRecordQueryBo bo) {
        PagePlus<ReportLoanRecord, ReportLoanRecordVo> result = pageVo(PageUtils.buildPagePlus(), buildQueryWrapper(bo), ReportLoanRecordVo.class);
        return PageUtils.buildDataInfo(result);
    }

    @Override
    public List<ReportLoanRecordVo> queryList(ReportLoanRecordQueryBo bo) {
        return listVo(buildQueryWrapper(bo), ReportLoanRecordVo.class);
    }

    private LambdaQueryWrapper<ReportLoanRecord> buildQueryWrapper(ReportLoanRecordQueryBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<ReportLoanRecord> lqw = Wrappers.lambdaQuery();
//        lqw.like(StrUtil.isNotBlank(bo.getProjName()), ReportLoanRecord::getProjName, bo.getProjName());
//        lqw.like(StrUtil.isNotBlank(bo.getBorrower()), ReportLoanRecord::getBorrower, bo.getBorrower());
		lqw.eq(null != bo.getProjId(), ReportLoanRecord::getProjId,bo.getProjId());
		lqw.eq(null != bo.getBorrowerId(),ReportLoanRecord::getBorrowerid,bo.getBorrowerId());
		lqw.eq(StringUtils.isNoneBlank(bo.getLoanNo()),ReportLoanRecord::getLoanNo,bo.getLoanNo());
        lqw.between(params.get("beginTransactionDate") != null && params.get("endTransactionDate") != null,
            ReportLoanRecord::getTransactionDate ,params.get("beginTransactionDate"), params.get("endTransactionDate"));
        return lqw;
    }


}
